"""
商店视图
最后修改：3.36
修改人：陈泯全
"""
from flask import Blueprint, request, json
from service.StoreService import storeService

bp = Blueprint("StoreSubSys", __name__, url_prefix="/StoreSubSys")


@bp.route('/')
def index():
    return {
        "stuatus": 'ok'
    }


# 药品列表
@bp.route('/MedcineList')
def medcinelist():
    storeservice = storeService()
    ds = storeservice.medcinelist()
    dict = {}
    dict['result'] = ds
    return dict


# 通过药品名字查找药品详情
@bp.route('/FindById')
def findbyid():
    # 获取传入的药品id 表单数据获取
    id = request.args.get('id')
    storeservice = storeService()
    ds = storeservice.findbyid(id)
    dict = {}
    dict['result'] = ds
    return dict


# 收藏列表
@bp.route('/CollectList')
def collectlist():
    # 获得当前用户的id
    uid = request.args.get('id')
    storeservice = storeService()
    ds = storeservice.collectlist(uid)
    dict = {}
    dict['result'] = ds
    return dict


# 添加收藏
@bp.route('/AddCollect')
def addcollect():
    # 获得当前用户的id
    uid = request.args.get('id')
    sid = request.args.get('sid')
    storeservice = storeService()
    ds = storeservice.addcollect(uid, sid)
    dict = {}
    dict['result'] = ds
    return dict


# 删除收藏
@bp.route('/DelCollect', methods=['GET', 'POST'])
def delcollect():
    # 获得需要删除的json数组
    data = json.loads(request.get_data(as_text=True))
    storeservice = storeService()
    ds = storeservice.delcollect(data)
    dict = {}
    dict['result'] = ds
    return dict


# 购买记录
@bp.route('/History')
def history():
    # 获得当前用户的id
    uid = request.args.get('id')
    storeservice = storeService()
    ds = storeservice.history(uid)
    dict = {}
    dict['result'] = ds
    return dict


# 获取购物车列表
@bp.route('/Shoppingcar')
def shoppingcar():
    # 获得当前用户的id
    uid = request.args.get('id')
    storeservice = storeService()
    ds = storeservice.shoppingcar(uid)
    dict = {}
    dict['result'] = ds
    return dict


# 加入购物车
@bp.route('/AddShoppingcar')
def addshoppingcar():
    # 获得当前用户的id
    uid = request.args.get('id')
    sid = request.args.get('sid')
    storeservice = storeService()
    ds = storeservice.addshoppingcar(uid, sid)
    dict = {}
    dict['result'] = ds
    return dict


# 移出购物车
@bp.route('/DelShoppingcar', methods=['GET', 'POST'])
def delshoppingcar():
    # 获得需要删除的json数组
    data = json.loads(request.get_data(as_text=True))
    storeservice = storeService()
    ds = storeservice.delshoppingcar(data)
    dict = {}
    dict['result'] = ds
    return dict


# 搜索商品
@bp.route('/Search')
def search():
    # 获得搜索框的内容
    str = request.args.get('str')
    storeservice = storeService()
    ds = storeservice.search(str)
    dict = {}
    dict['result'] = ds
    return dict
